package com.signway.module_signway_adapter_Api;

import android.content.Context;

import com.signway.open.api.IOpenUpdateApi;
import com.signway.opensdk.interfaces.base.Callback1;
import com.signway.opensdk.model.SDKResult;
import com.signway.opensdk.sdk.SDK;
import com.signway.utils.LogHelper;

import java.io.File;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2011-2019, by your Signway, All rights reserved.
 * -----------------------------------------------------------------
 *
 * ProjectName: droid5119
 *
 * Author: Administrator
 *
 * Email: pf.wang@Signway.cn
 *
 * Description:
 *
 * -----------------------------------------------------------------
 * 2019-5-30 : Create SignwayUpdateApi.java
 * -----------------------------------------------------------------
 */
public class SignwayUpdateApi implements IOpenUpdateApi {
    private static final String TAG = "SignwayUpdateApi";
    private static SignwayUpdateApi mSignwayUpdateApi;
    private static Context mContext;

    public static synchronized SignwayUpdateApi getInstance(Context context) {
        mContext = context;
        if (mSignwayUpdateApi == null) {
            mSignwayUpdateApi = new SignwayUpdateApi(context);
        }
        return mSignwayUpdateApi;
    }

    public SignwayUpdateApi(Context context) {
        this.mContext = context;
    }

    public void installAPKSilent(String path) {
        SDK.systemAPI().silentInstallApk(path, false, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("installAPKSilent result-->" + booleanSDKResult.getContent());
            }
        });
    }

    public void installAPKSilent(String path, String action) {
        SDK.systemAPI().silentInstallApk(path, false, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("installAPKSilent action result-->" + booleanSDKResult.getContent());
            }
        });
    }

    public void uninstallAPK(Context context, String packageName) {
        SDK.systemAPI().silentUninstallApk(packageName, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("uninstallAPK result-->" + booleanSDKResult.getContent());
            }
        });
    }

    public void setSystemCurrentTimeMillis(long current) {
    }

    public void updateOTA(String filePath) {
        SDK.updateAPI().updateOTA(filePath,new Callback1<SDKResult<Boolean>>(){

            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("updateOTA result-->" + booleanSDKResult.getContent());
            }
        });
    }
}
